package com.zax.servlet;

import com.zax.model.Page;
import com.zax.service.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
import java.net.URLEncoder;

@WebServlet("/goods_search")
public class GoodsSearchServlet extends HttpServlet {
//    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//
//    }
    private GoodsService gService = new GoodsService();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String keyword = request.getParameter("keyword");
        int pageNo = 1;
        if (request.getParameter("pageNo")!=null){
            pageNo = Integer.parseInt(request.getParameter("pageNo"));
        }
        Page p = gService.getSearchGoodsPage(keyword,pageNo);
        request.setAttribute("p" , p);
        request.setAttribute("keyword" , URLEncoder.encode(keyword,"utf-8"));
        request.getRequestDispatcher("/goods_search.jsp").forward(request,response);
    }
}
